<template>
  <div ref="lineChartRef" style="width: 100%; height: 250px"></div>
</template>

<script lang="ts" setup>
  import { ref, onMounted } from "vue";
  import * as echarts from "echarts";

  const lineChartRef = ref(null);

  onMounted(() => {
    if (lineChartRef.value) {
      const chart = echarts.init(lineChartRef.value);
      const option = {
        color: ["#5cc4a7", "#8170cb", "#f9a647", "#4bacc6"], // 扩展颜色方案
        tooltip: {
          trigger: "axis", // 折线图通常使用 axis 触发
          formatter: "{a} <br/>{b}: {c}", // 折线图不需要百分比
          backgroundColor: "rgba(50,50,50,0.9)",
          borderColor: "#333",
          textStyle: {
            color: "#fff",
            fontSize: 14,
          },
          extraCssText: "box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);",
        },

        xAxis: {
          type: "category",
          data: ["原材料获取", "原材料运输", "生产制造", "产品配送"], // 示例数据，根据实际情况修改
          axisLabel:{
            rotate:30, //倾斜角度
          }
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            name: "材料类别",
            type: "bar", // 修改为折线图
            data: [
              { value: 10, name: "原材料获取" },
              { value: 1, name: "原材料运输" },
              { value: 3, name: "生产制造" },
              { value: 1, name: "产品配送" },
            ],
            animationType: "scale", // 动画效果
            animationEasing: "elasticOut", // 弹性动画
            itemStyle: {
              borderRadius: [5, 5, 0, 0], // 圆角效果
              borderColor: "#fff",
              borderWidth: 1,
              shadowBlur: 8,
              shadowColor: "rgba(0, 0, 0, 0.1)",
            },
            animationDelay: function (idx) {
              return Math.random() * 200; // 随机延迟增加动感
            },
          },
        ],
        backgroundColor: "#fff", // 白色背景更专业
        textStyle: {
          fontFamily: "Arial, sans-serif", // 统一字体
        },
      };
      chart.setOption(option);
    }
  });
</script>
<style lang="scss" scoped></style>
